package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IUnrealTypeDao;
import com.hy.erp.inventory.dao.interfaces.IWorkingDao;
import com.hy.erp.inventory.pojo.UnrealType;
import com.hy.erp.inventory.pojo.User;
import com.hy.erp.inventory.pojo.Working;
import com.hy.erp.inventory.pojo.interfaces.IUnrealType;
import com.hy.erp.inventory.pojo.interfaces.IWorking;
import com.hy.erp.inventory.service.interfaces.IUnrealTypeService;

/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-27；时间：下午01:20:05</li>
 * <li>类型名称：UnrealTypeService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@Name("unrealTypeService")
@Scope(ScopeType.SESSION)
@Stateless
public class UnrealTypeService extends AbstractBusinessService < IUnrealType > implements IUnrealTypeService
{

	/**
	 * <ul>
	 * <li>开发作者：李冰</li>
	 * <li>设计日期：2010-10-27；时间：下午01:20:58</li>
	 * <li>字段类型：long；字段名称：serialVersionUID</li>
	 * <li>设计目的：</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 */
	private static final long	serialVersionUID	=
														3884514432459520385L ;

	@ Override
	public boolean addUnrealType (
									IUnrealType unrealType )
	{

		if ( null == unrealType)
		{
			return true ;
		}
		
		else
		{
			System.out
						.println ("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh") ;


			IUnrealTypeDao unrealTypeDao =
			                       ( IUnrealTypeDao ) this
			                                          .getDao ( IUnrealType.class ) ;
			
		
			return unrealTypeDao
			                .persist ( unrealType ) ;
		}
		
	
	
	}

	@ Override
	public boolean modifyUnrealType (
										IUnrealType unrealType )
	{




		if ( ( null == unrealType )
		     || ( null == unrealType
		                                .getIdentifier ( ) )
		     || ( unrealType
		                        .getIdentifier ( )
		                        .trim ( )
		                        .length ( ) == 0 ) )
		{
			return true ;
		}
		else
		{

			IUnrealTypeDao unrealTypeDao =
                ( IUnrealTypeDao ) this
                                   .getDao ( IUnrealType.class ) ;

			
				
			if ( null == unrealType )
			{
				throw new ArchitectureFoundationException  (
				                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			
			
			return ( unrealTypeDao
			                  .merge ( unrealType ) != null ) ;
		}
	
	
	
	
	}

	@ Override
	public Integer removeUnrealType (
										String [ ] unrealTypeIds )
	{


		if ( ( null == unrealTypeIds )
			     || ( unrealTypeIds.length == 0 ) )
		{
			return new Integer (
			                     0 ) ;
		}
		else
		{System.out
					.println (unrealTypeIds.length+"HHHHHHHHHHHHHH") ;
			
		IUnrealTypeDao unrealTypeDao =
            ( IUnrealTypeDao ) this
                               .getDao ( IUnrealType.class ) ;
			return unrealTypeDao
			                .remove ( unrealTypeIds ) ;
		}
		
	
	
	}

	@ Override
	public String [ ] addUnrealType (
										Object [ ] objects )
	{
		IUnrealTypeDao unrealTypeDao =
            ( IUnrealTypeDao ) this
                               .getDao ( IUnrealType.class ) ;
		UnrealType[] types=new UnrealType[objects.length];
		for(int i=0;i<objects.length;i++)
		{
			UnrealType type=( UnrealType ) objects[i];
			types[i]=type;
		}
		return unrealTypeDao.persist ( types ) ;
	}

	@ Override
	public List < UnrealType > getAllUnrealType ( )
	{
		IUnrealTypeDao unrealTypeDao =
            ( IUnrealTypeDao ) this
                               .getDao ( IUnrealType.class ) ;
		return unrealTypeDao.find ( ) ;
	}

	@ Override
	public String [ ] modifyUnrealType (
											Object [ ] objects )
	{
		if (  null == objects ) 
		{
			return null;
		}
		else
		{
			IUnrealTypeDao unrealTypeDao =
	            ( IUnrealTypeDao ) this
	                               .getDao ( IUnrealType.class ) ;
			UnrealType[] types=new UnrealType[objects.length];
            for(int i=0;i<objects.length;i++)
            {
            	UnrealType type=( UnrealType ) objects[i];
            	types[i]=type;
            }
			
			return unrealTypeDao.merge ( types );
		}
	}

}
